home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: Exceptions vs. assertions
- Date: 2 Jan 1996 14:26:20 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4cbfac$kst@dawn.mmm.com>
- References: <4al1hn$73e@news.nstn.ca> <4bpt9b$cb5@news2.ios.com> <4bqb7t$bca@sundog.tiac.net>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Chris Page (page@tiac.net) wrote:
- > lalit@gramercy.ios.com (lalit gidwani) wrote:
-
- > :Someone needs to point me to a proper architecture for using Exceptions.
- > :Several times I have come across articles that seem to apply that
- > :any time there is an error condition, an exception should be used.
- > :One of their arguments for doing this is that the program does
- > :not have to check for the return value of functions. The exception
- > :handling mechanism can be used instead. Since I have run into
- > :a lot of code where a lot of erro-checking has to be done I thought
- > :that exceptions would be helpful. However, the the note that appears
- > :above implies that C++ exception-handling should be used only
- > :for catastrophic errors.
-
- > :LG
-
- > Exceptions do not cost anything until you use them. My rule of thumb
-
- The truth of this statement is very dependent upon the implementation
- of exceptions in your system. But I have found that most implementations
- seem to strive toward this goal -- that performance of exception code
- compared with equivalent return-value code only suffers when exceptions
- are actually thrown.
-
- > is this: If I expect a condition to occur during normal operation of
- > my program, then I do not use exceptions for it. I use exceptions,
- > only for exceptionally conditions, which I do not expect to occur, but
- > I have to anticipate.
-
- This is a good approach. The issue of whether to throw exceptions or
- return status values is best decided by how likely the failure is than
- by how catastrophic it is. (Besides, the caller of a function knows
- better than the function itself how costly the failure is.)
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-